<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>键盘事件</title>
    <script src="../js/vue.js"></script>
  </head>
  <body>
    <div id="root">
      <h2>欢迎来到{{name}}学习</h2>
      <input type="text" placeholder="按下回车提示输入" @keyup.enter="showInfo" />
      <input type="text" placeholder="按下caps lock提示输入" @keyup.caps-lock="showInfo" />
      <input type="text" placeholder="按下 tab 提示输入" @keydown.tab="showInfo" />
      <input type="text" placeholder="按下 ctrl 提示输入" @keyup.ctrl="showInfo" />
      <input type="text" placeholder="按下 ctrl 提示输入" @keydown.ctrl="showInfo" />
      <input type="text" placeholder="按下回车提示输入" @keyup.13="showInfo" />
      <input type="text" placeholder="按下回车提示输入" @keyup.huiche="showInfo" />
      <input type="text" placeholder="按下 ctrl+y 提示输入" @keyup.ctrl.y="showInfo" />
      <input type="text" placeholder="按下 alt+y 提示输入" @keyup.alt.y="showInfo" />
      <!-- .enter 按键别名 -->
    </div>
  </body>
  <script>
    Vue.config.keyCodes.huiche = 13; // 自定义了一个回车按键

    new Vue({
      el: "#root",
      data() {
        return {
          name: "b站",
        };
      },
      methods: {
        showInfo(e) {
          // if(e.keyCode !== 13) return;
          console.log(e.target.value);
          // console.log(e.key,e.keyCode); //e.key 为按键名 e.keyCode 为按键码
        },
      },
    });
  </script> 
</html>
